/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var fieldLabel = new Array("序号","测点类别","监测点名称","监测点电压等级(kV)","监测装置装设具体位置","监测装置类型","监测装置厂家","监测装置型号","准确度等级","表号","SIM卡通讯号码","IP地址","通讯方式","监测装置有效期","责任部门","备注");
var fieldName=new Array("id","cdlb","jcdmc","jcddydj","jcdzzzsjtwz","jczzlx","jczzcj","jczzxh","jzddj","bh","SIMtxhm","IP","txfs","jczzyxq","zrbm","bz");
var record_start = 0;
            
Ext.QuickTips.init();
var _pageSize = 20;
var store;
var theme = '告警';
var now = new Date();


var pointTypeStore = new Ext.data.JsonStore({
    url: '../../servlet/common/SimpleInfoLoad',
    baseParams: {
        id: 'id', 
        name: 'name', 
        tableName: 't_pointType'
    },
    autoLoad: true,
    root: 'data',
    fields: ['id', 'name']
});

var pointTypeCombo = {
    xtype: 'combo',
    store: pointTypeStore,
    id: 'PointTypeCombo',
    displayField: 'name',
    valueField: 'id',
    hiddenName: 'pointTypeId',    
    mode: 'remote', 
    forceSelection: true,
    allowBlank: false,
    blankText: '不允许为空',
    triggerAction: 'all',
    fieldLabel: '监测点类型',
    emptyText: '请选择监测点类型...',
    selectOnFocus: true
}

var voltageLevelStore = new Ext.data.JsonStore({
    url: '../../servlet/common/SimpleInfoLoad',
    baseParams: {
        id: 'id', 
        name: 'name,lowerLimit,upperLimit', 
        tableName: 't_voltageLevel'
    },
    autoLoad: true,
    root: 'data',
    fields: ['id', 'name','lowerLimit','upperLimit']
});

var voltageLevelCombo = {
    xtype: 'combo',
    store: voltageLevelStore,
    id: 'VoltageLevelCombo2',
    displayField: 'name',
    valueField: 'id',
    hiddenName: 'voltagelLevelId',    
    mode: 'remote', 
    forceSelection: true,
    allowBlank: false,
    blankText: '不允许为空',
    triggerAction: 'all',
    fieldLabel: '电压等级',
    emptyText: '请选择电压等级...',
    selectOnFocus: true
};

function downloadExcel(){
    var PointType = PointTypeCombo.value;
    var VoltageLevel = VoltageLevelCombo2.value;
    params={
        VoltageLevel:VoltageLevel,
        PointType:PointType
    };
    var encodeParams = Ext.urlEncode(params);
    open('../../servlet/ExcelFileCreate?'+encodeParams);
}


function  buildWindow(){
    
    var data =[[fieldName[1],fieldName[1],fieldName[2],fieldName[3],fieldName[4],fieldName[5],fieldName[6],fieldName[7],fieldName[8],fieldName[9],fieldName[10],fieldName[11],fieldName[12],fieldName[13],fieldName[14],fieldName[15]]];
    store=new Ext.data.JsonStore({
        
        url: '../../servlet/report/device',
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName,
        autoLoad: true
        
    });
    colModel=new Ext.grid.ColumnModel({
        columns: [
        new Ext.grid.RowNumberer({
            header : fieldLabel[0],
            align: 'center', 
            width : 40,
            renderer: function (value, metadata, record, rowIndex) {
                return record_start + 1 + rowIndex;
            }
        }),

        {
            width : 140,
            header:fieldLabel[1],
            dataIndex:fieldName[1],
            socrtable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[2],
            dataIndex:fieldName[2],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[3],
            dataIndex:fieldName[3],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[4],
            dataIndex:fieldName[4],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[5],
            dataIndex:fieldName[5],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[6],
            dataIndex:fieldName[6],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[7],
            dataIndex:fieldName[7],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[8],
            dataIndex:fieldName[8],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[9],
            dataIndex:fieldName[9],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[10],
            dataIndex:fieldName[10],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[11],
            dataIndex:fieldName[11],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[12],
            dataIndex:fieldName[12],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[13],
            dataIndex:fieldName[13],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[14],
            dataIndex:fieldName[14],
            sortable:true,
            align: 'center'
        },

        {
            width : 140,
            header:fieldLabel[15],
            dataIndex:fieldName[15],
            sortable:true,
            align: 'center'
        },     
        ],
        defaultSortable: true
    });
    
    
    
    var grid = new Ext.grid.GridPanel({
        title: '电压监测装置台帐表',
        store: store,
        colModel:colModel,
        enableColumnMove: false,
        
        viewConfig: {
            forceFit: false
        },
        
        loadMask: true,
        tbar: new Ext.Toolbar([
        {
            text: "监测点类型：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        
        pointTypeCombo,     
        '-',
        {
            text: "测点电压等级：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            },
            forceSelection: true,
            allowBlank: false,
            blankText: '不允许为空',
            triggerAction: 'all',
            fieldLabel: '监测点类型',
            emptyText: '请选择监测点类型...',
            selectOnFocus: true
        },
        voltageLevelCombo, 
        '-',
        {
            xtype: 'button',
            text: '搜索',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: function() {
                store.load({
                    params: {
                        start: 0, 
                        limit: _pageSize
                    }
                });
            }
        },
        '-',
        {
            xtype: 'button',
            text: '导出',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: downloadExcel
        },
        ]),
        bbar: new Ext.PagingToolbar({
            pageSize: _pageSize,
            store: store,
            displayInfo: true,
            displayMsg: '显示记录：{0} - {1}   总记录：{2}',
            emptyMsg: "目前没有" + theme + '信息'
        })
    });
    store.load({
        params: {
            start: 0, 
            limit: _pageSize
        }
    });
    
    var applicationUI = new Ext.Viewport({
        layout: "fit",
        items: [
        grid
        ]
    });
}
Ext.onReady(buildWindow);  